 <!DOCTYPE html>
 
<%@ page import="java.sql.*" %> 
<%@ page import="java.io.*" %> 
<%@ page import="java.util.Date" %> 
<%@ page import="java.text.DateFormat" %> 
<%@ page import="java.text.SimpleDateFormat" %> 


<% 
try {
	
	String connectionURL = "jdbc:mysql://localhost:3306/unilearn"; 
	
	int c_row_count = 0;
	Connection connection = null;
	Statement stmt = null;
	ResultSet rst=null;

	Class.forName("com.mysql.jdbc.Driver").newInstance(); 

	connection = DriverManager.getConnection(connectionURL, "root", "");
	stmt = connection.createStatement();
	
	if(!connection.isClosed())
	{
		
		String assign_name=request.getParameter("txtAssignmentName");
		String s_dd = request.getParameter("cboStartDateDD");
		String s_mm = request.getParameter("cboStartDateMM");
		String s_yy = request.getParameter("cboStartDateYY");
		String e_dd = request.getParameter("cboEndDateDD");
		String e_mm = request.getParameter("cboEndDateMM");
		String e_yy = request.getParameter("cboEndDateYY");
		String assign_status = request.getParameter("cboAssigStatus");
		String upload_file = request.getParameter("spec_assignment");
		String desc = request.getParameter("txtdescription");
		String assign_type = request.getParameter("cboAssignmentType");
		String class_group = request.getParameter("cboClassGroup");
		
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date _now = new Date();
		
		
		String full_s_date = "";
		String full_e_date = "";
		if (s_dd != "" && s_mm != "" && s_yy != "")
		{
			 full_s_date = s_yy + "-" + s_mm + "-" + s_dd + " 00:00:00";
		}
		
		if (e_dd != "" && e_mm != "" && e_yy != "")
		{
			full_e_date = e_yy + "-" + e_mm + "-" + e_dd + " 00:00:00";
		}
			
		if((assign_name != null && assign_name != ""))
		{ 
			c_row_count = stmt.executeUpdate("INSERT INTO assignment (assignment_name, assignment_status , assignment_type, class_group_id, start_date, end_date, spec_file_path, description, create_user, create_date, modify_date )" 
			+ "VALUES ('"+assign_name+"', '"+assign_status+"', '"+assign_type+"', '"+class_group+"', '"+full_s_date+"', '"+full_e_date+"', '"+upload_file+"', '"+desc+"', '1', '"+ dateFormat.format(_now) +"', '"+dateFormat.format(_now)+"')");
			
			
			if (c_row_count > 0)
			{
				out.println( "<script>alert('assignment create successful')</script>" );
			}else
			{
				out.println( "<script>alert('assignment create failed')</script>" );
			}
		}
	}
%>

<html lang="en">
<head>
<script type="text/javascript">
	function check_filed(assign_name){
		
		if(assign_name.value == "" || assign_name.value == null )
		{
			alert("assignment name is empty please input");
			return false;
		}
	}
</script>
<link rel="stylesheet" type="text/css" href="common.css">
<title>Assignmenr Create</title>
</head>
<body>
<form action="assignmentCreate.jsp" method="post" name="entry" onSubmit="return validate(this)">
<table class="TblBody" style="width:720px">
	<tr>
		<td>
			<div class="contentb">
				<table width="100%">
                    <tr>
                        <td style="background-color:#ccff99; font-size:20px; font-weight:bold; height:30px">Assignment Create</td>
                    </tr>
					<tr>
						<td style=" font-size:15px; font-weight:bold">
							<table width="100%">
							    <tr>
							        <td style="width:8%"><a href="assignment.html">Assigment</a></td>
							        <td style="width:3%">&nbsp;/&nbsp;</td>
							        <td style="width:12%"><a href="administrator.html">Discuss Barod</a></td>
							        <td style="width:3%">&nbsp;/&nbsp;</td>
							        <td style="width:13%"><a href="personalSetting.html">Personal Setting</a></td>
							        <td style="width:49%"></td>
							        <td style="color:#666666; font-size:11px">Hello! <span><u>Tutor 1</u></span></td>
							    </tr>
							</table>
							<hr />
						</td>
					</tr>
					<tr>
                        <td>
                            <table width="100%">
                                <tr>
                                    <td style="width:16%">Assignment Name</td>
                                    <td><input name="txtAssignmentName" type="text" /></td>
                                </tr>
                                <tr>
                                    <td>Start Date</td>
                                    <td>
                                        <select name="cboStartDateDD">
                                            <option value="1">01</option>
                                            <option value="2">02</option>
											<option value="3">03</option>
											<option value="4">04</option>
											<option value="5">05</option>
											<option value="6">06</option>
											<option value="7">07</option>
											<option value="8">08</option>
											<option value="9">09</option>
											<option value="10">10</option>
											<option value="11">11</option>
											<option value="12">12</option>
											<option value="13">13</option>
											<option value="14">14</option>
											<option value="15">15</option>
											<option value="16">16</option>
											<option value="17">17</option>
											<option value="18">18</option>
											<option value="19">19</option>
											<option value="20">20</option>
											<option value="21">21</option>
											<option value="22">22</option>
											<option value="23">23</option>
											<option value="24">24</option>
											<option value="25">25</option>
											<option value="26">26</option>
											<option value="27">27</option>
											<option value="28">28</option>
											<option value="29">29</option>
											<option value="30">30</option>
											<option value="31">31</option>
                                        </select>
                                        &nbsp; / &nbsp;
                                        <select name="cboStartDateMM">
                                            <option value="1">01</option>
                                            <option value="2">02</option>
											<option value="3">03</option>
											<option value="4">04</option>
											<option value="5">05</option>
											<option value="6">06</option>
											<option value="7">07</option>
											<option value="8">08</option>
											<option value="9">09</option>
											<option value="10">10</option>
											<option value="11">11</option>
											<option value="12">12</option>
                                        </select>
                                        &nbsp; / &nbsp;
                                        <select name="cboStartDateYY">
                                            <option value="2011">2011</option>
                                            <option value="2012">2012</option>
											<option value="2013">2013</option>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td>End Date</td>
                                    <td>
                                        <select name="cboEndDateDD">
                                            <option value="1">01</option>
                                            <option value="2">02</option>
											<option value="3">03</option>
											<option value="4">04</option>
											<option value="5">05</option>
											<option value="6">06</option>
											<option value="7">07</option>
											<option value="8">08</option>
											<option value="9">09</option>
											<option value="10">10</option>
											<option value="11">11</option>
											<option value="12">12</option>
											<option value="13">13</option>
											<option value="14">14</option>
											<option value="15">15</option>
											<option value="16">16</option>
											<option value="17">17</option>
											<option value="18">18</option>
											<option value="19">19</option>
											<option value="20">20</option>
											<option value="21">21</option>
											<option value="22">22</option>
											<option value="23">23</option>
											<option value="24">24</option>
											<option value="25">25</option>
											<option value="26">26</option>
											<option value="27">27</option>
											<option value="28">28</option>
											<option value="29">29</option>
											<option value="30">30</option>
											<option value="31">31</option>
                                        </select>
                                        &nbsp; / &nbsp;
                                        <select name="cboEndDateMM">
                                            <option value="1">01</option>
                                            <option value="2">02</option>
											<option value="3">03</option>
											<option value="4">04</option>
											<option value="5">05</option>
											<option value="6">06</option>
											<option value="7">07</option>
											<option value="8">08</option>
											<option value="9">09</option>
											<option value="10">10</option>
											<option value="11">11</option>
											<option value="12">12</option>
                                        </select>
                                        &nbsp; / &nbsp;
                                        <select name="cboEndDateYY">
                                            <option value="2011">2011</option>
                                            <option value="2012">2012</option>
											<option value="2013">2013</option>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td>Assigment Status</td>
                                    <td>
                                        <select name="cboAssigStatus">
                                            <option value="1">Open</option>
                                            <option value="0">Close</option>
                                        </select>
                                    </td>
                                </tr>
								<tr>
									<td>Assignment Type</td>
									<td>
									<select name="cboAssignmentType">
                                            <option value="1">local</option>
											<option value="2">Team</option>
                                     </select>
									 </td>
								</tr>
								<tr>
									<td>Class Group</td>
									<td>
									<select name="cboClassGroup">
                                            <option value="1">41303-1A</option>
											<option value="2">41303-1B</option>
                                     </select>
									 </td>
								</tr>
                                <tr>
                                    <td>Specification</td>
                                    <td>
                                        <input name="spec_assignment" type="file" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>Description</td>
                                    <td>
                                        <textarea name="txtdescription" cols="50" rows="7"></textarea>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <input id="btnSubmit" type="submit" onClick="check_filed(txtAssignmentName)" value="Submit" />&nbsp;&nbsp;
                                        <input id="btnReset" type="reset" value="reset" />
                                    </td>
                                </tr>
                            </table>
                        </td>
					</tr>
				</table>
			</div>
		</td>
	</tr>
</table>
</form>
<%
}catch(Exception ex){

	out.println(ex);
}
%>
</body>
</html>